module.exports = function ({Articles, sequelize}) {

    /**
     * 统计分析 V2
     */
    Articles.analyseV2 = function () {
        let sql = "select type, count(*) count from Articles group by type";
        return sequelize.query(sql, {
            type: sequelize.QueryTypes.SELECT
        });
    }

    /**
     * 更新浏览次数
     */
    Articles.updateViewCountV2 = function ({id}) {
        let sql = "update Articles set view_count = view_count + 1 where id = :id";
        return sequelize.query(sql, {
            replacements: {id: id}
        }).spread(function (res) {
            if (!res.affectedRows) {
                return {success: false};
            }
            return {success: true};
        });
    }
}